package com.individual.spring.cloud.gateway.demo.config;


import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.gateway.filter.GlobalFilter;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.annotation.Order;
import reactor.core.publisher.Mono;

@Slf4j
@Configuration
@RequiredArgsConstructor
public class GlobalFiltersConfiguration {

    @Bean
    @Order(1)
    public GlobalFilter a() {
        return (exchange, chain) -> {
            log.info("filter start");
            return chain.filter(exchange).then(Mono.fromRunnable(() -> {
                log.info("filter end");
            }));
        };
    }

    @Bean
    @Order(0)
    public GlobalFilter b() {
        return (exchange, chain) -> {
            log.info("second filter start");
            return chain.filter(exchange).then(Mono.fromRunnable(() -> {
                log.info("second filter end");
            }));
        };
    }
//
//    @Bean
//    @Order(1)
//    public GlobalFilter c() {
//        return (exchange, chain) -> {
//            log.info("third pre filter");
//            return chain.filter(exchange).then(Mono.fromRunnable(() -> {
//                log.info("first post filter");
//            }));
//        };
//    }
}
